package com.wxm.killing.mq.bme;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 封装请求参数
 * @author: wxm
 * @date: 2019/10/23 23:28
 * @version: 1.0
 */
@Data
public class BmeParam {
    //精确匹配
    public static final String EQUALS = "equals";

    //模糊匹配
    public static final String LIKE = "like";

    //区间范围
    public static final String RANGE = "range";

    private Map<String, Object> mapParam = new HashMap<>();

    /**
     * 添加精确匹配条件
     *
     * @param key
     * @param value
     * @return
     */
    public BmeParam putEquals(String key, Object value) {
        return put(EQUALS, key, value);
    }

    /**
     * 添加模糊匹配条件
     *
     * @param key
     * @param value
     * @return
     */
    public BmeParam putLike(String key, Object value) {
        return put(LIKE, key, value);
    }

    /**
     * 添加区间查询条件
     *
     * @param key
     * @param value
     * @return
     */
    public BmeParam putRange(String key, Object value) {
        return put(RANGE, key, value);
    }

    public BmeParam put(String type, String key, Object value) {
        if (mapParam.containsKey(type)) {
            Map<String, Object> mapTemp = (Map<String, Object>) mapParam.get(type);
            mapTemp.put(key, value);
        } else {
            Map<String, Object> mapTemp = new HashMap<>();
            mapTemp.put(key, value);
            mapParam.put(type, mapTemp);
        }
        return this;
    }

    public BmeParam put(String key, Object value) {
        mapParam.put(key, value);
        return this;
    }
}
